const fs = require("fs");

const { themeList, getBlockSchema, writeFile } = require("../tool/util");

function main() {
    let blocks = {};
    const list = themeList();
    list.forEach((template) => {
        const sections = fs.readdirSync(`./src/theme/${template}/sections`);
        sections.forEach((section) => {
            const schemaConfig = getBlockSchema(`./src/theme/${template}/sections/${section}`);
            const blockTypeName = section.replace(".liquid", "");
            const currentBlock = {
                template: template,
                imgUrl: `/theme/${template}/assets/${blockTypeName}.jpg`
            };
            if (!blocks[blockTypeName]) {
                blocks[blockTypeName] = {
                    name: schemaConfig.name.zh_CN,
                    section: blockTypeName,
                    list: [currentBlock]
                };
            } else {
                blocks[blockTypeName].list.push(currentBlock);
            }
        });
    });
    writeFile("./app/mock/template_block_all.js", "module.exports = " + JSON.stringify(blocks, "", "\t"));
}

main();
